package com.leetroll.app.controller;

import com.leetroll.api.service.ChapterService;
import com.leetroll.app.utils.AppJwtTokenUtil;
import com.leetroll.common.bean.ApiResponse;
import com.leetroll.common.vo.ChapterVO;
import com.leetroll.common.vo.ItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@RestController
@RequestMapping("/chapter")
@Api(value = "章节视频接口", tags = {"章节视频接口"})
@Slf4j
public class ChapterController {
    private final ChapterService chapterService;
    private final AppJwtTokenUtil jwtTokenUtil;

    @Autowired
    public ChapterController(ChapterService chapterService, AppJwtTokenUtil jwtTokenUtil) {
        this.chapterService = chapterService;
        this.jwtTokenUtil = jwtTokenUtil;
    }

    @ApiOperation(value = "item详情", notes = "item详情")
    @GetMapping("/{itemId}")
    public ApiResponse<List<ChapterVO>> get(HttpServletRequest request, @PathVariable Long itemId) {
        Long userId = jwtTokenUtil.getUserId(request);
        List<ChapterVO> vos = chapterService.getAllByItemId(itemId);
        return ApiResponse.OK(vos);
    }

}
